package org.springcloud.wisdom.spring_01_canteen.address;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressService {
    @Autowired
    private AddressDao addressDao;
    //查看地址
    public List<Address> getAllAddresses(Integer stuid, String status) {
        // 调用canaddress方法，并传递stuid和status参数
        return addressDao.canaddress(stuid, status);
    }

    //更新地址
    public boolean update(Address address){
        if (address == null){
            return false;
        }
        return addressDao.update(address)>0;
    }

    //菜品删除（根据id）
    public boolean del(Integer id){
        if (id==null){
            return false;
        }
        return addressDao.del(id)>0;
    }

    //地址增加
    public boolean add(Address address){
        if (address == null){
            return false;
        }
        return addressDao.add(address)>0;
    }

    // 设置默认地址
    public void setDefaultAddress(Integer id) {
        // 重置所有地址的status为0
        addressDao.resetAllStatusesToNonDefault();
        // 将指定ID的地址status设置为1
        addressDao.setDefaultAddressStatus(id);
    }
}
